<template>
  <div>
    <!-- Swiper -->
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div
          class="swiper-slide"
          v-for="(item, index) in list"
          :key="index"
          @click="go"
        >
          <div class="imgCon">
            <img :src="item" alt="" />
          </div>
          <span class="text">美食</span>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import Swiper from "swiper";
import "swiper/swiper-bundle.min.css";

import a from "../assets/swiperIcon/a.png";
import b from "../assets/swiperIcon/b.png";
import c from "../assets/swiperIcon/c.png";
import d from "../assets/swiperIcon/d.png";
import e from "../assets/swiperIcon/e.png";
import f from "../assets/swiperIcon/f.png";

export default {
  data() {
    return {
      list: [a, b, c, d, e, f, b, a, c, d, e, f, a, b, c, d],
    };
  },
  methods: {
    go() {
      console.log(123);
    },
  },
  created() {
    this.$nextTick(() => {
      new Swiper(".swiper-container", {
        slidesPerView: 3,
        slidesPerColumn: 2,
        spaceBetween: 30,

      });

      // 创建实例时会根据有多少数据将每个的宽度预留好，但因为循环需要时间，因此需要通过this.$nextTick
    });
  },
};
</script>

<style scoped>
img {
  width: 50px;
  height: 50px;
  display: block;
  margin: 0 auto;

 
}
html,
body {
  position: relative;
  height: 100%;
}

body {
  background: #eee;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #000;
  margin: 0;
  padding: 0;
}

.text {
  width: 40px !important;
  height: 40px;
  font-size: 14px;
}
.swiper-container {
  width: 100%;
  height: 100%;
  margin-left: auto;
  margin-right: auto;
}
.swiper-wrapper {
  width: 100%;
  height: 200px;
}
.swiper-slide {
  text-align: center;
  font-size: 18px;
  /* background: pink; */
  height: calc((100% - 30px) / 2);

  /* Center slide text vertically */
  /* text-align: center; */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: block;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}
</style>